/**============================================================================
 Confidential Information - Limited distribution to authorized persons only.
 This software is protected as an unpublished work under the U.S. Copyright
 Act of 1976.

 Copyright (c) 2011, BluePhoenix Solutions, Inc. All rights reserved.
 ----------------------------------------------------------------------------
 file......: removeableEditText.java
 Author....: Vyacheslav Kovalyov
 Created...: 12/29/11

 Description:

 ============================================================================*/
package com.bphx.android.activities.views;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import com.bphx.android.ui.listeners.IActionListener;
import com.bphx.android.ui.ITextView;

import static android.content.Context.LAYOUT_INFLATER_SERVICE;
import static com.bphx.android.R.id.deleteImage;
import static com.bphx.android.R.id.removeableEditText;
import static com.bphx.android.R.layout.removeable_edit_text;
import static com.bphx.android.utils.Utils.getTextFrom;

/**
 * @author Vyacheslav Kovalyov
 * @version 1.0
 */
public class RemovableEditText extends LinearLayout implements ITextView {

    public RemovableEditText(Context context, final IActionListener<View> removeListener) {
        super(context);

        LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
        layoutInflater.inflate(removeable_edit_text, this);

        editText = (EditText) findViewById(removeableEditText);

        findViewById(deleteImage).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                removeListener.dispatchAction(RemovableEditText.this);
            }
        });
    }

    @Override
    public String getText() {
        return getTextFrom(editText);
    }

    @Override
    public void setText(String text) {
        editText.setText(text);
    }

    private EditText editText;
}

